home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / internet / web-related / apache_1.0.5 / cgi-src / post-query.c < prev    next >
Text File  |  1996-02-16  |  2KB  |  57 lines

  1.  
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. #define MAX_ENTRIES 10000
  8.  
  9. typedef struct {
  10.     char *name;
  11.     char *val;
  12. } entry;
  13.  
  14. char *makeword(char *line, char stop);
  15. char *fmakeword(FILE *f, char stop, int *len);
  16. char x2c(char *what);
  17. void unescape_url(char *url);
  18. void plustospace(char *str);
  19.  
  20.  
  21. main(int argc, char *argv[]) {
  22.     entry entries[MAX_ENTRIES];
  23.     register int x,m=0;
  24.     int cl;
  25.  
  26.     printf("Content-type: text/html%c%c",10,10);
  27.  
  28.     if(strcmp(getenv("REQUEST_METHOD"),"POST")) {
  29.         printf("This script should be referenced with a METHOD of POST.\n");
  30.         printf("If you don't understand this, see this ");
  31.         printf("<A HREF=\"http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html\">forms overview</A>.%c",10);
  32.         exit(1);
  33.     }
  34.     if(strcmp(getenv("CONTENT_TYPE"),"application/x-www-form-urlencoded")) {
  35.         printf("This script can only be used to decode form results. \n");
  36.         exit(1);
  37.     }
  38.     cl = atoi(getenv("CONTENT_LENGTH"));
  39.  
  40.     for(x=0;cl && (!feof(stdin));x++) {
  41.         m=x;
  42.         entries[x].val = fmakeword(stdin,'&',&cl);
  43.         plustospace(entries[x].val);
  44.         unescape_url(entries[x].val);
  45.         entries[x].name = makeword(entries[x].val,'=');
  46.     }
  47.  
  48.     printf("<H1>Query Results</H1>");
  49.     printf("You submitted the following name/value pairs:<p>%c",10);
  50.     printf("<ul>%c",10);
  51.  
  52.     for(x=0; x <= m; x++)
  53.         printf("<li> <code>%s = %s</code>%c",entries[x].name,
  54.                entries[x].val,10);
  55.     printf("</ul>%c",10);
  56. }
  57.